package mylib.dir;

/**
 * Created with IntelliJ IDEA.
 * User: 1
 * Date: 02.08.12
 * Time: 20:59
 * To change this template use File | Settings | File Templates.
 */
public class Point {

    public int x, y;

    public Point(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public Point add(Point other) {
        return new Point(x + other.x, y + other.y);
    }

    public Point subtract(Point other) {
        return new Point(x - other.x, y - other.y);
    }

    public double length() {
        return Math.sqrt((long) x * x + (long) y * y);
    }

    public long hypot() {
        return (long) x * x + (long) y * y;
    }

    public Point mul(int m) {
        return new Point(x * m, y * m);
    }

    public Point divide(int m) {
        return new Point(x / m, y / m);
    }

    public double distance(Point other) {
        return Math.sqrt(Math.pow(x - other.x, 2) + Math.pow(y - other.y, 2));
    }

    public Point negate() {
        return new Point(-x, -y);
    }

    public static boolean leftRotate(Point a, Point b, Point c) {
        return (b.subtract(a)).multiply(c.subtract(b)) > 0;
    }

    public static boolean rightRotate(Point a, Point b, Point c) {
        return (b.subtract(a)).multiply(c.subtract(b)) < 0;
    }

    public static boolean collinear(Point a, Point b, Point c) {
        return Math.abs(b.subtract(a).multiply(c.subtract(b))) == 0;
    }

    public long multiply(Point other) {
        return GeometryUtils.determinant(x, y, other.x, other.y);
    }

    @Override
    public String toString() {
        return "{" +
                "x=" + x +
                ", y=" + y +
                '}';
    }

    public PointF toPointf() {
        return new PointF(x, y);
    }
}